﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace KeyboardImageViewer
{
    /// <summary>
    /// Compares the full names of the two FileInfo objects in ASCII order (to mimic SQLite)
    /// </summary>
    public class FileInfoNameComparer : IComparer<FileInfo>
    {
        public int Compare(FileInfo x, FileInfo y)
        {
            string stringX = x.FullName.ToLowerInvariant();
            string stringY = y.FullName.ToLowerInvariant();

            for (int i = 0; i < stringX.Length && i < stringY.Length; i++)
            {
                if (stringX[i] < stringY[i])
                {
                    return -1;
                }
                else if (stringX[i] > stringY[i])
                {
                    return 1;
                }
            }

            if (stringX.Length < stringY.Length)
            {
                return -1;
            }

            if (stringX.Length > stringY.Length)
            {
                return 1;
            }

            return 0;
        }
    }
}
